import axios from "axios";

const httpInstance = axios.create({
  baseURL: '/',
  timeout: 5000
});

// 请求拦截器
httpInstance.interceptors.request.use(config => {
  // 从本地存储中获取 token
  const token = localStorage.getItem('token');
  if (token) {
    // 在请求头中添加 token
    config.headers['Authorization'] = ` ${token}`;
  }
  return config;
}, e => Promise.reject(e));

// 响应拦截器
httpInstance.interceptors.response.use(res => res.data, e => {
  return Promise.reject(e);
});

export default httpInstance;

